# Simple HTML ?

**URL:** https://boards.straightdope.com/t/simple-html/430499
**Category:** Factual Questions
**Created:** [December 18, 2007, 8:58pm UTC](https://boards.straightdope.com/t/simple-html/430499 "2007-12-18T20:58:48Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)
#### Post date: [December 18, 2007, 8:58pm UTC](https://boards.straightdope.com/t/simple-html/430499/1 "2007-12-18T20:58:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [December 18, 2007, 9:00pm UTC](https://boards.straightdope.com/t/simple-html/430499/2 "2007-12-18T21:00:57Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [December 18, 2007, 9:09pm UTC](https://boards.straightdope.com/t/simple-html/430499/3 "2007-12-18T21:09:43Z")

</div>

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](http://www.webmonkey.com/webmonkey/98/04/index3a_page4.html) that should help you.

---

<div class="post-metadata">

### Author: ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)
#### Post date: [December 18, 2007, 9:20pm UTC](https://boards.straightdope.com/t/simple-html/430499/4 "2007-12-18T21:20:34Z")

</div>

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:

```auto

<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:

```auto

<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.

---

<div class="post-metadata">

### Author: ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)
#### Post date: [December 18, 2007, 9:36pm UTC](https://boards.straightdope.com/t/simple-html/430499/5 "2007-12-18T21:36:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)
#### Post date: [December 18, 2007, 9:41pm UTC](https://boards.straightdope.com/t/simple-html/430499/6 "2007-12-18T21:41:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [December 18, 2007, 9:41pm UTC](https://boards.straightdope.com/t/simple-html/430499/7 "2007-12-18T21:41:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [December 18, 2007, 9:43pm UTC](https://boards.straightdope.com/t/simple-html/430499/8 "2007-12-18T21:43:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)
#### Post date: [December 18, 2007, 10:10pm UTC](https://boards.straightdope.com/t/simple-html/430499/9 "2007-12-18T22:10:34Z")

</div>

[QUOTE=ZipperJJ]  
document.getElementById(“Input1”).value

[/QUOTE]

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.

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [December 18, 2007, 10:17pm UTC](https://boards.straightdope.com/t/simple-html/430499/10 "2007-12-18T22:17:07Z")

</div>

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;

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [December 19, 2007, 2:18pm UTC](https://boards.straightdope.com/t/simple-html/430499/11 "2007-12-19T14:18:10Z")

</div>

Did it work?

---

<div class="post-metadata">

### Author: ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)
#### Post date: [December 19, 2007, 3:02pm UTC](https://boards.straightdope.com/t/simple-html/430499/12 "2007-12-19T15:02:28Z")

</div>

[QUOTE=jjimm]  
Did it work?  
[/QUOTE]  
Just got back to work. Yep it worked. Thanks everyone.

enipla
