Simple HTML ?

I have an Input text box thus….
<input id=“Input1” style=“width: 99px” type=“password” language=“javascript” />

and a hyper link
<a ID=“HyperLink1” href=“Management1.aspx?CMD=” ’ + Input1.value + “’”>HyperLink</a>

All I want to do is pass the value of Input1 as a variable to the Command CMD in Management1.aspx. I can’t seem to form the syntax right for Input1.value, it remains blank.

Thanks

Why is “language” in your input text? I’ve never seen that before. From my limited knowledge, in the absence of context, that’s never going to work.

Do you have an “onClick” action, or a “submit” button? Does the hyperlink get written by an onClick or JS action?

On further thought, I think you’re crediting JavaScript with more than it actually does.

“Input1.value” doesn’t get populated until you’ve told JavaScript to write that value to the hyperlink. And to extract that value from the text field, you need an event - onFocus or onBlur. Extracting the value requires a function too. Then you need to write to the HREF - which in itself it quite involved.

There’s an excellent tutorial about forms starting here that should help you.

Javascript doesn’t work that way.

In order to pass the form value to Management1.aspx, there are a few options.

  1. Change the link into a form submit button:


<form method="GET" target="Management1.aspx">
  <input id="Input1" style="width: 99px" type="password" name="CMD" />
  <input type="submit" value="Submit" />
</form>


  1. If you really want to use a link rather than a form submit button, then you can use some Javascript to make the hyperlink submit the form behind the scenes:


<form method="GET" target="Management1.aspx">
  <input id="Input1" style="width: 99px" type="password" name="CMD" />
  <a href="#" onclick="document.forms[0].submit()">Hyperlink</a>
</form>


  1. Finally, if you really don’t want to use a form, you could do some DOM manipulation to dynamically add the form value to a real link. But I suspect that’s a tad overkill for your purposes.

I’m working in VS. language = javascript was what the control was defaulted to when I dragged it out of the toolbox.

hmmmm… I tried this.
function DoIt()
{
var test = window.document.Input1.value
return
}

<input id=“Input1” onblur=“DoIt();” style=“width: 99px” type=“password” />

This returns the error window.document.Input1.value is null or not an object.

If it’s really Javascript, you want

document.getElementById(“Input1”).value

and/or give the element a name too (name=Input1), but i think in that case you still have to add the form name between document and element:

document.formname.Input1.value

It won’t recognise the input value until you have told it that Input1 is part of a form in the document - refer to the link I posted earlier.

ETA: or do what ZipperJJ said, which skips the need for the form, I think.

BTW, this question is nothing whatsoever to do with simple HTML!

Hokay,

This worked.

function DoIt()
{
document.getElementById(“Input1”).value
return
}

Now I just need to pass it as a var to the hyperlink…

Something like this?

<a ID=“HyperLink1” href=“Management1.aspx?CMD=javascript:DoIt();”>HyperLink</a>

Only it’s not calling the function.

I will also try using a form submit.

You can’t embed a function in a hyperlink.

Write a function triggered by an “onClick” in your HREF, that adds the input value to a variable, then calls that as a window.location.

E.g. your HREF looks something like: <a ID=“HyperLink1” href="#" onClick=“DoIt();”>Hyperlink</a>

Then DoIt includes:

var TheFirstBit = “Management1.aspx?CMD=”;
var TheVariable = document.getElementById(“Input1”).value;
var TheURL = TheFirstBit + TheVariable;
window.location = TheURL;

Did it work?

Just got back to work. Yep it worked. Thanks everyone.

enipla