PDA

View Full Version : [RESOLVED] Form - Changing form action, name of input etc dynamically.


redinferno
12-12-2008, 03:36 PM
I have a drop down menu. When the user selects a certain item from the drop down menu i want to make the form's "action" property and the "name" property of certain input fields change.

Example: If they select "billing" I want the forms action to change to "billing.php" so that when they click the login button they will be taken to "billing.php".

Here is the XHTML code I am using so far.

<form action="#" id="LoginForm">
<div>
<input type="submit" id="submit" value="">
<input type="text" class="textbox" id="username" name="username" value="username">
<input type="password" class="textbox" id="password" name="password" value="******">
<select id="PanelSelection">
<option onfocus="ChangeFormBilling()"> Billing Panel </option>
<option onchange="ChangeFormGame()"> Game Panel </option>
<option onchange="ChangeFormVoice()"> Voice Panel </option>
</select>
</div>
</form>


and this is the javascript i am using.


function ChangeFormBilling()
{
document.getElementById("LoginForm").action = "billing.php";
document.getElementById("username").name = "billinguser";
document.getElementById("password").name = "billingpass";
}

function ChangeFormGame()
{
document.getElementById("LoginForm").action = "game.php";
document.getElementById("username").name = "gameuser";
document.getElementById("password").name = "gamepass";
}

function ChangeFormVoice()
{
document.getElementById("LoginForm").action = "voice.php";
document.getElementById("username").name = "voiceuser";
document.getElementById("password").name = "voicepass";
}

dchard05
12-12-2008, 04:01 PM
so your saying that your codes are not doing what they suppose to do?

redinferno
12-12-2008, 04:18 PM
I found out what I was doing wrong. I was using the wrong event.

<option onclick="ChangeFormBilling()"> Billing Panel </option>
<option onclick="ChangeFormGame()"> Game Panel </option>
<optiononclick="ChangeFormVoice()"> Voice Panel </option>

If you look at my old post I was using onfocus and onchange.