tags:

views:

673

answers:

3
Name  <input type="text" id="Name" name="Name">
Password<input type="password" id="Password" name="Password">

<a href="file:///home/naveen/Desktop/imp/nav2.html?Name="+document.MyForm.getElementById('Name').value;"Password"+document.MyForm.getElementById('Password').value;">

Please help

A: 

You can't eval Javascript in a hyperlink reference. You will need to use an onclick handler, like so:

Name  <input type="text" id="Name" name="Name">
Password<input type="password" id="Password" name="Password">

<a href="javascript:location.href='file:///home/naveen/Desktop/imp/nav2.html?Name='+document.MyForm.getElementById('Name').value+'&Password='+document.MyForm.getElementById('Password').value';">Go</a>

By the way, even if href did eval Javascript, that line was so full of errors that it wouldn't have worked anyway.

Charlie Somerville
A: 

You could create a global variable called urlExtension and override the OnChange events of both text boxes. You can then start to build up the url i.e.

var urlExtension = "";
var mainUrl = "file:///home/naveen/Desktop/imp/nav2.html?"

function OnNameChange()
{
    urlExtension = "Name=" + document.getElementById('Name').value;
    UpdateURL();
}

function OnPasswordChange()
{
    urlExtension += "&Password=" + document.getElementById('Password').value;
    UpdateURL();
}

function UpdateURL()
{
    document.getElementById('MyLink').getElementsByTagName('a')[0].href = mainUrl + urlExtension;
}

I would perhaps advise wrapping your < a href> tag within a span and give it a unique ID, so you can specify which specific link you want to update...Something like:

Name  <input type="text" id="Name" name="Name" onchange="OnNameChange()">
Password<input type="password" id="Password" name="Password" onchange="OnPasswordChange()">
<span id='MyLink'><a href="#">Go to URL</a></span>

However, it is not a good idea to be passing sensitive information such as a password as plain txt!

James
+1  A: 
<script langauage="Javascript">
function Go()
{
    location.href = 'MyUrl.asp?name=' + document.getElementByID("name").value;
}
</script>


<input type="text" name="name">
<a href="javascript:void(0)" onclick="javascript:Go()">Click here to go...</a>
Bhaskar
You don't need the javascript: URL scheme in the onclick handler. I don't even know if that will execute.
Charlie Somerville