Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with JS form

Status
Not open for further replies.

robertritz

Technical User
Mar 3, 2010
3
US
I am very new to javascript and this is what I have cobbled together. When I am testing it out it doesn't do anything at all, just reloads. I have tried several display methods and nothing seems to work. Thanks.

<html>
<head>
<title>Generate URL for Shared Outlook Calendar</title>
<script language="Javascript" type="text/javascript">
<script>
function urlgenerator()
{

textstring = '';
name = document..getElementById("firstname").value;
lname = document.getElementById("lastname").value;
cname = document.getElementById("calendarname").value;
textstring += ' + name + '.' + lname + '@unt.edu/?cmd=contents&f=' + cname;
document.forms["urlgen"].output.value=textstring
}
window.onload = urlgenerator;
</script>
</head>
<body>
<form>
<form name="urlgen">
<h1 ID="head1">Create URL for Shared Outlook Calendar</h1>
<p>Fill out the form below to generate a URL for a shared Outlook calendar.</p>
<form name="example" action="#" onsubmit="checkit(); return false">
<table class="form">
<tr>
<td>First Name</td>
<td><input type="text" id="firstname" value=""></td>
</tr>

<tr>
<td>Last Name</td>
<td><input type="text" id="lastname" value=""></td>
</tr>

<tr>
<td>Calendar Name</td>
<td><input type="text" id="calendarname" value=""></td>
</tr>

<input type="submit" value="Generate URL" onsubmit="Javascript:urlgenerator()" />

</form>
</body>
</html>
 
1. you have 3 nested forms, 2 of which you never end/close </form>, that is surely going to cause problems.
2. Neither of your forms have an element inside them called 'output'.

Yet you attempt to set its value to a string made up of the concatenation of the other form element values but since there is no object with the name 'output' it can't set anything.

3. You are submitting the form, so of course its resetting the page. That's what submitting does, it loads the page in the action property of the form tag and passes the form values to it, when the property is absent, it re-loads the current page and passed the form values to it.
Since you have 3 forms, its hard to tell which one is getting submitted, but its surely not the 'example' form.

4. Your third form named 'example' is told to run a function called 'checkit()' which does not exist anywhere in your code and then cancel the form submission via the return false; statement.

5. Your submit button is attempting to have the function urlgenerator() be run when its onsubmit event is triggered, however submit buttons don't have an onsubmit event, only forms have such an event, as only forms can be submitted.

Most of these issues would display errors either in FF's error console or in Internet Explorers error icon on the bottom left corner of the browser.

With that said, what is it you are attempting to do, perhaps then we could help you out more than just pointing out everything that's wrong.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I am trying to concatenate the input from several fields into a URL that is displayed in an alert window or in a text box (preferable). I know how to create a text box, just can't figure out how to output my textstring to that box. I made some changes to the code. Here it is. Thanks for the help, sorry for the ridiculous mistakes.

<html>
<head>
<title>Generate URL for Shared Outlook Calendar</title>
<script language="Javascript" type="text/javascript">
<script>
function urlgenerator()
{

textstring = '';
name = document..getElementById("firstname").value;
lname = document.getElementById("lastname").value;
cname = document.getElementById("calendarname").value;
textstring += ' + name + '.' + lname + '@unt.edu/?cmd=contents&f=' + cname;
document.forms["urlgen"].output.value=textstring
}
window.onload = urlgenerator;
</script>
</head>
<body>
<form name="urlgen" obsubmit="Javascript:urlgenerator()">
<h1 ID="head1">Create URL for Shared Outlook Calendar</h1>
<p>Fill out the form below to generate a URL for a shared Outlook calendar.</p>
<table class="form">
<tr>
<td>First Name</td>
<td><input type="text" id="firstname" value=""></td>
</tr>

<tr>
<td>Last Name</td>
<td><input type="text" id="lastname" value=""></td>
</tr>

<tr>
<td>Calendar Name</td>
<td><input type="text" id="calendarname" value=""></td>
</tr>

<input type="submit" value="Generate URL">
<output \\not sure what to put here

</form>
</body>
</html>
 
Create the textbox, and set its value just like you are doing.

New code still has some errors, here this should work:

Code:
<html>
<head>
<title>Generate URL for Shared Outlook Calendar</title>
<script language="Javascript" type="text/javascript">
function urlgenerator()
{
textstring = '';
name = document.getElementById("firstname").value;
lname = document.getElementById("lastname").value;
cname = document.getElementById("calendarname").value;
textstring += '[URL unfurl="true"]https://webmail.unt.edu/OWA/'[/URL] + name + '.' + lname + '@unt.edu/?cmd=contents&f=' + cname;
document.forms["urlgen"].output.value=textstring;
}

</script>
</head>
<body>
<form name="urlgen">
<h1 ID="head1">Create URL for Shared Outlook Calendar</h1>
<p>Fill out the form below to generate a URL for a shared Outlook calendar.</p>
<table class="form">
<tr>
<td>First Name</td>
<td><input type="text" id="firstname" value=""></td>
</tr>

<tr>
<td>Last Name</td>
<td><input type="text" id="lastname" value=""></td>
</tr>

<tr>
<td>Calendar Name</td>
<td><input type="text" id="calendarname" value=""></td>
</tr>

<input type="submit" value="Generate URL" onClick="urlgenerator(); return false;">
<input type=text name="output">

</form>
</body>
</html>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks a bunch! Not I am going to work on adding if's. Hopefully I can get that going.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top