Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a form to a link outside the form tags

Status
Not open for further replies.

an0n3099

Programmer
Joined
Apr 14, 2006
Messages
3
Location
US
I have a rather large web application I am developing and I'm trying to create a toolbar near the top of the page to make things more centralized and user friendly. Now the problem is that I have a form farther down in the page and I'm trying to get the current input selected (in this case a radio button) passed to the link above in the toolbar. Any ideas on how this can be done?

Here is the related code I have so far:

function get_form(form) {
var input = form.client_choice.value;
alert ("You typed: " + input);
}

<div id="toolbar">
<!-- the alert displays: "You typed: undefined" -->
<a href="#" onclick="get_form(fClients)">Open</a> |
<a href="#">History</a>
</div>

<form name="fClients">
<tr class="table-row-1">
<td><input type="radio" name="client_choice" value="client 1" /></td>
<td align="left">client 1</td>
</tr>
<tr class="table-row-2">
<td><input type="radio" name="client_choice" value="client 2" /></td>
<td align="left">client 2</td>
</tr>
</form>
 
You have to manually check to see which radio was selected:

Code:
alert(form.elements['client_choice'][0].checked);
alert(form.elements['client_choice'][1].checked);

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes that helped a lot. Thank you for the quick reply Dan.
 
For future reference:

function get_form(form, element_name) {
for (i = 0; i < form.elements[element_name].length; i++)
if (form.elements[element_name].checked)
user_input = form.elements[element_name].value;

alert(user_input);
}

onclick = "get_form(fClients, 'client_choice')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top