Computing.Net > Forums > Programming > Need help using variable in FORM

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need help using variable in FORM

Reply to Message Icon

Name: suspect52732
Date: January 27, 2005 at 11:55:37 Pacific
OS: XP
CPU/Ram: 2.4/512
Comment:

I am tring to display the title of the page in my form.

Currently, I can do this with javascript and display the title in other places on the page, but not in the form. I am posting the simple code to help understand what I am saying.

--------------------

<head>
</head>
<body>

<SCRIPT LANGUAGE="JavaScript">
document.write(document.title)
</script>


<form>
<input type="text" value=javascript:document.write(document.title) />
</form>

</body>
</html>


------------------


You can see from the code, that I am displaying the variable on the page.

Then I am tring to display the variable in a FORM. It doesn't work in the form becuase I don't know the syntax for displaying a variable in a form.


Any help is greatly appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: Rolos
Date: January 27, 2005 at 21:36:03 Pacific
Reply:

You might be better off storing the value of document.title in a variable, then printing the value with document.write(). For instance:

var docTitle = document.title;
document.write(<form> ... + docTitle + ... </form>);

Doing this might be considered trivial, however it would make your script more readable. Here is a more elegant solution to your problem:

<body>
<script>
document.write("<form><input type = 'text' value = '" + document.title + "'/></form>");
</script>
</body>

Give that a try. I hope this helps you on your HTML project. Good luck.

- Rolos



0

Response Number 2
Name: Michael J (by mjdamato)
Date: January 27, 2005 at 23:26:34 Pacific
Reply:

Here is an easy solution. Put a Javascript block at the end of the page (or at least after the field to be populated) and update the value instead of trying to populate it within the tag itself.

Example:

<script>
document.forms[0].fieldName.value =   document.title;
</script>

fieldName needs to be the name of the form field you are populating.

forms[0] can be replaced with the name you gave the form. If you have more than 1 form on the page you will need to either use the form name or the correct form itteration in the brackets.

Michael J


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Need help using variable in FORM

i need help in using dtpicker in Access www.computing.net/answers/programming/i-need-help-in-using-dtpicker-in-access/1538.html

I need help in date picker in Access97 www.computing.net/answers/programming/i-need-help-in-date-picker-in-access97/1520.html

I need help writing code in VB5 www.computing.net/answers/programming/i-need-help-writing-code-in-vb5/18297.html