1

Am using Liferay portal 6.1.1 CE.

In my liferay portlets jsp page - view.jsp, I have a form with 2 textfields and 2 radio buttons (user can select only one) and a submit button.

When I click on any of the radio buttons, control goes to a script function which is working properly.

Now I want to pass the values of 2 textfields to the script function. I tried a lot, but no use.

How can I achieve this?

Help me..Thanks in advance.

<script>
    function dif()
    {

    }
</script>
<form name="<portlet:namespace/>fm" method="post" action="<%=updateBookURL.toString()%>">
    <table>
        <tr>
            <th>Leave Application</th>
        </tr>
        <tr>
            <td>Employee <font color=red>*</font></td>
            <td>
                <input type="text" name="<portlet:namespace/>name"/>
                <input type="text" name="<portlet:namespace/>eid"  />
        </tr>

            <td>
                Date <font color=red>*</font>
                <input type="text" id="<portlet:namespace/>fd" name="<portlet:namespace/>
            </td>
            <td>
            <input type="radio" name="<portlet:namespace/>f" id="f" value="1st half" onClick="f()"/>
            First Half&=
            <input type="radio" name="<portlet:namespace/>f" id="f" value="2ndhalf" onClick="f()"/>
            Second Half
            </td>
        </tr>

        <tr>
            <td></td>
            <td><input type="submit" value="save data" size="100px"/></td>
        </tr>
    </table>
</form>
2
  • Now when I have formatted I noticed there is a </td> and a <tr> missing. Formatting helps, isn't it! :-) Commented Dec 11, 2012 at 7:48
  • Its ok..but i need the way to pass the values to the function.. Commented Dec 11, 2012 at 7:56

2 Answers 2

3

Getting the value of the text in javascript function is nothing new in liferay it is plain old javascript, following are some links and examples which would help you (the code which I have written would go in your custom function you define within the <script> ... </script> tags):

  1. Get input text value using:

    var fdTextValue = document.getElementById("<portlet:namespace/>fd").value;
    
  2. Get input text value using jQuery (the only problem with this is you have to include jQuery library in your portlet or theme, since starting from Liferay-6 you have Alloy UI included by default):

    var fdTextValue = $("#<portlet:namespace/>fd").val();
    /* or */ 
    var fdTextValue = $("#<portlet:namespace/>fd").attr('value');
    
  3. Get input text value using Alloy UI of Liferay:

    AUI().use(function(A) {
        var fdTextValue = A.one('#<portlet:namespace/>fd').get('value');
        /* or */ 
        var fdTextValue = A.one('#<portlet:namespace/>fd').val();
    });
    

    Some of the following links might also help you using Alloy UI:

    1. Working with Elements and Events with Alloy UI.
    2. Alloy UI API
Sign up to request clarification or add additional context in comments.

Comments

0

It is very simple.

on click event of then in js define this function.

<script>
function callFun()
{
      // Here you can use jquery easily
      var name = $("#name").val();
      alert(name);
}
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.