Submit form using text

Is it possible to use text to submit its value and other entries on a form to another page. An example would be the word 'Computers' when clicked submits the value 'Computers' and a text box and dropdown menu values also. I know you can use javascript to use text to submit a form but I want the value of the text also. Any ideas if this is possible and how to go about it? Thanks
gingerwingerAsked:
Who is Participating?
 
COBOLdinosaurConnect With a Mentor Commented:
Oh!... Oops..

The link needs to be:

<a href="#" onclick="document.forms['form1'].SubCatagory.value='Computers'" class="roll2">

I drilled down to the element, and then left out the property (value)

Cd&
0
 
COBOLdinosaurCommented:
I'm sorry I don't understand what is is you are trying to do.  Are you trying to submit a for using a link?

Cd&

0
 
gingerwingerAuthor Commented:
I have several text options that a user can select each looking like the following <a href="SubCatDetails.asp?SubCatagory=Computers" class="roll2" onClick="document.form1.submit()">Computers</a>    I want each one to be able to submit its details and a text box and drop down menu value. Is this possible?  Thanks
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
COBOLdinosaurCommented:
It is possible to submit just about anything with scripting, but we need to see code, or a link to the page.

Cd&
0
 
gingerwingerAuthor Commented:
Here is the code for the form on the first page. I want the postcode, mileage and the text selected to be submitted to the next page so it can search those criteria. I would like it so that by selecting the text submits the form and its info also:

<form name="form1" method="post" action="SubCatDetails.asp">
              <table width="85%" border="0" cellspacing="0" cellpadding="5">
                <tr>
                  <td><font color="#FF9900" size="3" face="Arial, Helvetica, sans-serif">1)
                      Select a postcode</font></td>
                  <td><input name="yapostcode" type="text" id="yapostcode"></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><font color="#FF9900" size="3" face="Arial, Helvetica, sans-serif">2)
                      Select a distance willing to travel</font></td>
                  <td><select name="yadistance" id="yadistance">
                    <option value="0.1">10
                    <option value="0.2">20
                    <option value="0.2">30
                    <option value="0.4">40
                    <option value="0.5">50
                  </select>
                    </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><font color="#FF9900" size="3" face="Arial, Helvetica, sans-serif">3)
                      Select a Category</font></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="37%"><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computer%20Accessories" class="roll2" onClick="this.form.submit()">Computer
                        Accessories</a></font></td>
                  <td width="20%"><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computer%20Repairs" class="roll2">Computer
                        Repairs</a></font></td>
                  <td width="43%"><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Consoles" class="roll2">Consoles</a></font></td>
                </tr>
                <tr>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computer%20Aided%20Design%20Services" class="roll2">Computer
                        Aided Design Services</a></font></td>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computer%20Services" class="roll2">Computer
                        Services</a></font></td>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Internet%20and%20Web%20Design" class="roll2">Internet &amp; Web
                        Design</a></font></td>
                </tr>
                <tr>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computer%20Games" class="roll2">Computer
                        Games</a></font></td>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computer%20Tuition" class="roll2">Computer
                        Tuition</a></font></td>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
                </tr>
                <tr>
                  <td height="27"><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computer%20Rentals" class="roll2">Computer
                        Rentals</a></font></td>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="SubCatDetails.asp?SubCatagory=Computers" class="roll2" onClick="document.form1.submit()">Computers</a></font></td>
                  <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
                </tr>
              </table>
              <input type="submit" name="Submit" value="Submit">
              </form>

What I want to do is when the user fills in the postcode and mileage and then selects a category this will submit the three sets of information.

For the second page there are three Recordsets which filter the info provided. I can get them working if I ignore the category selection so I know the postcode bit works ok. Its just submitting the category info that causes problems.

<%
Dim rsPostcode2__MMColParam
rsPostcode2__MMColParam = "1"
If (Request.Form("yapostcode")  <> "") Then
  rsPostcode2__MMColParam = Request.Form("yapostcode")
End If
%>
<%
Dim rsPostcode2
Dim rsPostcode2_numRows

Set rsPostcode2 = Server.CreateObject("ADODB.Recordset")
rsPostcode2.ActiveConnection = MM_Postcode_STRING
rsPostcode2.Source = "SELECT *  FROM postcodes  WHERE postcode LIKE '%" + left(rsPostcode2__MMColParam, 4) + "%'"
rsPostcode2.CursorType = 0
rsPostcode2.CursorLocation = 2
rsPostcode2.LockType = 1
rsPostcode2.Open()

rsPostcode2_numRows = 0
%><br>

<%
Dim rsDistance__long1
rsDistance__long1 = "1"
If (rsPostcode2.Fields.Item("longitude").Value <> "") Then
  rsDistance__long1 = rsPostcode2.Fields.Item("longitude").Value
End If
%>
<%
Dim rsDistance__lat1
rsDistance__lat1 = "1"
If (rsPostcode2.Fields.Item("latitude").Value <> "") Then
  rsDistance__lat1 = rsPostcode2.Fields.Item("latitude").Value
End If
%>
<%
Dim rsDistance__dist
rsDistance__dist = "1"
If (Request.Form("yadistance") <> "") Then
  rsDistance__dist = Request.Form("yadistance")
End If
%><br>

<%
Dim rsDistance
Dim rsDistance_numRows

Set rsDistance = Server.CreateObject("ADODB.Recordset")
rsDistance.ActiveConnection = MM_Postcode_STRING
rsDistance.Source = "SELECT *  FROM postcodes  WHERE longitude BETWEEN " + Replace(rsDistance__long1, "'", "''") + " + " + Replace(rsDistance__dist, "'", "''") + " AND " + Replace(rsDistance__long1, "'", "''") + " - " + Replace(rsDistance__dist, "'", "''") + " AND latitude BETWEEN " + Replace(rsDistance__lat1, "'", "''") + " + " + Replace(rsDistance__dist, "'", "''") + " AND " + Replace(rsDistance__lat1, "'", "''") + " - " + Replace(rsDistance__dist, "'", "''") + ""
rsDistance.CursorType = 0
rsDistance.CursorLocation = 2
rsDistance.LockType = 1
rsDistance.Open()

rsDistance_numRows = 0
%>
<%
Dim rsLocation__MMColParam
rsLocation__MMColParam = "1"
If (Request.QueryString("SubCatagory") <> "") Then
  rsLocation__MMColParam = Request.QueryString("SubCatagory")
End If
%>
<%
Dim yapostcodes
Do While Not rsDistance.Eof
If rsDistance("Postcode")<>"" Then
yapostcodes = yapostcodes &"'" & rsDistance("Postcode")& "'" & ","
End If
rsDistance.MoveNext()
Loop
yapostcodes = Left(yapostcodes, Len(yapostcodes)-1)
%>
<%
Dim rsLocation
Dim rsLocation_numRows

Set rsLocation = Server.CreateObject("ADODB.Recordset")
rsLocation.ActiveConnection = MM_Advert_STRING
rsLocation.Source = "SELECT *  FROM Advert INNER JOIN CustDetails ON  Advert.CustId = CustDetails.CustId  WHERE CustPostcode IN (" & yapostcodes & ") AND SubCategory = '" + Replace(rsLocation__MMColParam, "'", "''") + "'"

rsLocation.CursorType = 0
rsLocation.CursorLocation = 2
rsLocation.LockType = 1
rsLocation.Open()

rsLocation_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsLocation_numRows = rsLocation_numRows + Repeat1__numRows
%>

I hope you understand what I am trying to achieve here. If not please get back to me. Thanks for you time with this. Maybe you will be able to sort it and I can then sleep at night!! :-))

Cheers



0
 
COBOLdinosaurCommented:
You are having a problem because you are submitting the for with the two inputs, and then linking to teh asp with the category stuff.  you have to do it all of the submit.  Add a hideen input for catagory:

<input type="hidden" name="SubCatagory"

Then change the links to this format:

<a href="#" onclick="document.forms['form1'].SubCatagory='Computer Rentals'" class="roll2">Computer Rentals</a>

Cd&
0
 
gingerwingerAuthor Commented:
Hi

I have tried that and it doesn't work. All I get is a warning message in the bottom window of explorer saying 'Error on Page'.

It does not move to the next page either.  Any ideas?

Thanks again
0
 
COBOLdinosaurCommented:
Well I guess we can start by finding out what the error is..  in the tools menu select internet options; click the advanced tab, and you will get a list of checkboxes.  Check the one that says Display notification of every script error.  Now try it a gain and let my know what the error is.

Cd&
0
 
gingerwingerAuthor Commented:
Line: 155
Char: 1
Error: Object doesn't support this property or method
Code: 0

Hope you know what this means cos I don't!

Thanks again
0
 
COBOLdinosaurCommented:
I'll need a link to the page, so I can see what the browser has on that line.

Cd&
0
 
gingerwingerAuthor Commented:
Unfortunately I'm working on a local server so you won't be able to see that line but if its the same as in Dreamweaver the line 155 is:

Line 155: <td><font color="#000066" size="2" face="Arial, Helvetica, sans-serif"><img src="pics/arrow.gif" width="10" height="12"><a href="#" onclick="document.forms['form1'].SubCatagory='Computers'" class="roll2">Computers</a></font></td>
0
 
gingerwingerAuthor Commented:
Well now no error occurs but absolutely nothing happens! Any ideas?
0
 
COBOLdinosaurCommented:
Well the action on the form is:SubCatDetails.asp

If you do not get an error on the submit saying the page does not exist, then the form is being submitted to it and the problem is in the asp that is processing the form and return the response page.  

I thought you had that part working.  I don't do ASP, so I don't know what might be wrong, but you are submitting the form.

Cd&
0
 
gingerwingerAuthor Commented:
When I click on the text nothing happens. It stays on the same page but changes the URL to computers.asp# instead of going to SubCatDetails.asp.
0
 
COBOLdinosaurCommented:
Right you want the sumit off the link. Okay:

<a href="#" onclick="document.forms['form1'].SubCatagory='Computers';document.forms['form1'].submit();return false;" class="roll2">Computers</a>

That should do it.

Cd&
0
 
gingerwingerAuthor Commented:
Sorry my friend that doesn't work either! I get the same line error as before but the error this time is as follows:

Document.forms.form1.submit() is null or not an object.

The good thing though is that it goes to the SubCatDetails page but doesn't return any results.

Many thanks
0
 
COBOLdinosaurCommented:
Then the form is not being generated correctly or you have a typo.  I have to see the as it is on the browser.  pull the page into you browser..view source.. and cut and paste the code here.

Cd&
0
 
gingerwingerAuthor Commented:
YEEEHAAA!! I got it to work! I had a look at the code and it was a typo.  Then I cut and paste your code you did earlier and it came up with the same message as before: Object doesn't support this property or method.

Having this come up before I looked at the code and you had missed off the .value from the code. I put it in and hey presto it works!!!

I can't thank you enough. Thanks for being patient with me and for all your help.
0
 
gingerwingerAuthor Commented:
Slight problem! I can't use any form validation with DW to make sure a user fills in the two other fields. Maybe it has something to do with the way the forms submitted. Any ideas?
0
 
COBOLdinosaurCommented:
If Dreamweaver cannot do i, then you will have to write a validation function on the client and validate before you submit, or dig around in Dreamweaver to see if you can determine why it is that limited in support of this.

Cd&
0
 
gingerwingerAuthor Commented:
Hi

I have placed a submit button in the form to submit it instead of the text and it brings up the message no probs.  It just seems to be ignoring the way I am using the text to submit the form.  I have no experience of Javascript and confused as to what to do for the best.

Any ideas why it's ignoring the text or could you point me in the direction on how to validate one text field on submit so it will work

Regards

Dan
0
 
COBOLdinosaurCommented:
I have to see the page, to be able to help.

Cd&
0
 
gingerwingerAuthor Commented:
I have managed to change the 'return false' part of the <a href="#" onclick="document.forms['form1'].SubCategory.value='Computers';document.forms['form1'].submit();return false;" class="roll2">Computers</a>

with

 YY_checkform('form1','yapostcode','#q','0','Field \'yapostcode\' is not valid.','yadistance','#q','1','Field \'yadistance\' is not valid.');return document.MM_returnValue

This manages to bring up a warning box saying that the fields have not been completed correctly but still goes to the SubCatDetails.asp page after you click ok in the error box.

I'm nearly there but I can't stop the submit if fields are filled in incorrectly. HELP!!! :-)

Thanks for your help with this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.