Page 1 of 1

Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 8:16 am
by nightswore
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


So I'm working on this search function for a status page I've made. Basically it uses a little javascript to have the user select their input from a popup calendar. Not too difficult really, and not my problem. Once implimented however, I don't have a good way to submit the data in the fields they fill out because both fields require a <form> tag to complete their action, and because of this, I can't seem to put a <form> tag completely around the two statements so that I can then post the information with a submit button, once I put the <form> tag before the first javascript popup, it stops working and I have nothing to submit. The javascript looks like this (this is without the script commands in the header):

Code: Select all

   <td>Start Date :</td>
    <td>
    
    <FORM NAME="start">
<INPUT TYPE="text" NAME="date1" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['start'].date1,'anchor1','MM/dd/yyyy'); return false;"
   NAME="anchor1" ID="anchor1">Select</A>
</FORM></td>
<td>End Date :</td>
    <td>
    <FORM NAME="end">
<INPUT TYPE="text" NAME="date1" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['end'].date1,'anchor1','MM/dd/yyyy'); return false;"
   NAME="anchor1" ID="anchor1">Select</A>
</FORM></td>
 
So you can see that it starts with a form and then does a lot of javascript ten closes the form and then moves to the next object. What I need to do is somehow get both of those inputs tied to a submit button that would basically be where this code ends. If anyone has any tricks or ideas, I'd appreciate the input.

If any clarification is needed, I can provide some, I'm always bad at explaining my problem well, haha.


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 9:48 am
by mabwi
Is there any reason both javascript objects can't be in the same form? And they just write to different fields?

Re: Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 9:52 am
by nightswore
The form names are part of what the script uses to process the information, that is why they're named 'start' and 'end'.

I tried it anyway and it didn't seem to like it, got a pop up warning message instead of my calendar.

Re: Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 9:56 am
by pickle
Your <form> tags can't start in one cell & end in another - that might be your problem. Wrap that whole table in <form></form> tags & try to submit it.

Re: Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 10:18 am
by nightswore
Yes...you...can? I do it all the time...

Re: Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 10:37 am
by pickle
If you can, it's only because the browser you're using is smart enough to recover from bad coding practices. Try validating the source code of that page & see what happens.

Re: Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 10:45 am
by mabwi
nightswore wrote:The form names are part of what the script uses to process the information, that is why they're named 'start' and 'end'.

I tried it anyway and it didn't seem to like it, got a pop up warning message instead of my calendar.
What if you renamed the elements within the form. Like so:

Code: Select all

 
 
<FORM NAME="calendarcontrol">
<table><tr>
<td>Start Date</td>
<td>
<INPUT TYPE="text" NAME="startdate" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['calendarcontrol'].startdate,'anchor1','MM/dd/yyyy'); return false;"
   NAME="anchor1" ID="anchor1">Select</A>
</td>
</tr><tr>
<td>End Date :</td>
    <td>
<INPUT TYPE="text" NAME="enddate" VALUE="" SIZE=25>
<A HREF="#"
   onClick="cal.select(document.forms['calendarcontrol'].enddate,'anchor2','MM/dd/yyyy'); return false;"
   NAME="anchor2" ID="anchor2">Select</A>
</td>
</tr></table>
</FORM> 
 
One form, two controls, each with a distinct name. This should work, unless the Javascript is doing something wacky.

Re: Difficulty with multiple <form>s

Posted: Thu Jul 24, 2008 10:50 am
by nightswore
Thanks, but it got to the point where I jus found a different javascript, haha. Thanks though!