...

View Full Version : Button Vs HyperLink



Crash1hd
11-07-2003, 01:56 PM
The following code is giving me trouble?

<%

response.write "<P Class=SubTitle><A HREF='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"' onClick=""this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';"" Target=_Blank>Click Here to view what the Memorial will look like!</A><BR />No password checks will be used</p><br />"

response.write "<input type='submit' value='Go Back' onClick=""this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';"">"

%>

the button works fine yet the hyperlink gives me a javascript error that says

'this.form' is null or not an object

then when the page loads none of the form fields get transmitted?

Also how do I get a button to open in a new window useing target without putting the target in the form field? cause I will be useing the form fields for multiple links!

Roy Sinclair
11-07-2003, 03:52 PM
"this.form" only works for form field elements, not just any element between the <form> and </form> tags. You need to use another mechanism to get to the form object from within a link tag.

M@rco
11-08-2003, 03:47 PM
That's true, but more to the point, why are you setting the form's .action property in the hyperlink at all?

:p

Crash1hd
11-08-2003, 09:45 PM
To have multiple links in the Form! that reflect to the form

M@rco
11-09-2003, 01:43 AM
Originally posted by Crash1hd
To have multiple links in the Form! that reflect to the form I can make no sense of that, I'm afraid!! What do you mean "reflect"?

:confused:

My point was that you are setting the .action property of the form from within the link, but you aren't calling the .submit() method, so it's not actually achieving anything.!! It's also duplicating the code in the onclick event of the submit button...!

Basically, the URL within the href is perfectly adequate.

;)

Crash1hd
11-09-2003, 04:12 AM
Ok here is the code! Broken down!



<form action="Purchase_Mem.asp?dbshow=4" method="post">

<input type="hidden" name="submitnumber" value="<%=submitnumber%>">

<select size="1" name="PurchaseField" onchange="this.form.action='Purchase_Mem.asp?dbshow=2&backcheck=1&PurchaseField='+this.options[this.selectedIndex].value;this.form.submit();">

<%

response.write "<P Class=SubTitle><A HREF='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"' onClick=""this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';this.form.submit();"" Target=_Blank>Click Here to view what the Memorial will look like!</A><BR />No password checks will be used</p><br />"

response.write "<P Class=SubTitle><input type='submit' value='Go Back' onClick=""this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';""></p>"

%>

<td align="center">
<input type="submit" value="Confirm">&nbsp;&nbsp;&nbsp;
<input type="submit" value="Go Back" onClick="this.form.action='Purchase_Mem.asp?dbshow=4&PurchaseField=<%=Request.Querystring("purchasefield")%>';">
</td>
</tr>
</table>
</form>



I understand that this

<%

response.write "<P Class=SubTitle><A HREF='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"' onClick=""this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';"" Target=_Blank>Click Here to view what the Memorial will look like!</A><BR />No password checks will be used</p><br />"

%>

should be this

<%

response.write "<P Class=SubTitle><A HREF='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"' onClick=""this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';this.form.submit();"" Target=_Blank>Click Here to view what the Memorial will look like!</A><BR />No password checks will be used</p><br />"

%>

But I still get the javascript error?

M@rco
11-09-2003, 12:48 PM
Your code is making less and less sense the more I see of it!

1) If the user lets the form load and presses Confirm, then dbshow=4 will be passed in the querystring, and PurchaseField= (no value) will be passed as part of the form POST. Why on earth do you want that?

2) Your <select> element contains no <option> elements, and therefore doesn't give the user anything to choose from, and won't pass any values. It also lacks a closing </select> tag.

3) In this line:
response.write "<P Class=SubTitle><A HREF='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"' onClick=""this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';this.form.submit();"" Target=_Blank>Click Here to view what the Memorial will look like!</A><BR />No password checks will be used</p><br />"You are still trying to use this.form to get a reference to the form object despite Roy telling you that's not going to work (in post #2 in this thread)!! And my point about the script in the onclick event being useless still remains. So here's a different approach... is there a good reason why you CAN'T do this:
response.write "<P Class=SubTitle><A HREF='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"' Target=_Blank>Click Here to view what the Memorial will look like!</A><BR />No password checks will be used</p><br />"

4) Although it's not technically required for HTML, you should ensure that all attribute values are enclosed in quotes (preferably the same type too), which you are not currently doing - see the Class and Target attributes above.


There's more I could say, but I'll leave it there. Please respond to the points above (and re-read the other posts in this thread), and then explain in words exactly what you are trying to do on this page - i.e. what the purpose of each of the select element, links, and buttons is/are.

;)

Crash1hd
11-09-2003, 02:37 PM
Lol :) The code that I gave is only a fraction of the entire code the entire code is over 3000 lines long its a really large page! I am going to quote another post I had done in javascripts as to what I want to do!



http://www.codingforums.com/showthread.php?s=&postid=147695#post147695


I will have form fields that after you fill in and click submit it goes to a confirm page on that confirm page there will be a link at the bottem that says click here to view sample of what it will look like in not so many words! When you click that link it opens a small page with everything in the form that you entered! After the user likes what they see they close it which puts them back on the main page at the bottem has to buttons complete and go back when you click on those buttons it takes the same form info to the next page but not in a new window! Which is why i am unable to use a button for the samples cause to make it open into a new window the form field has to look as follows

<form action="webpage" method="post" target="_Blank">

The problem with that is that all the buttons would open a new page, so I have to use a link that I can specify how it opens new page or not! yet I always get an error useing a link instead of a button however I have used dropdowns which would reload the page and onload with specific info it will open the new page but I would rather not have to use a dropdown and have to refresh the page!

I hope that makes sense

I understand that it can seem to be vague with what I had given for information however If I where to post the entire code well lets just say short of uploading a file I wont be able to do that! :)

I hope that helps!:thumbsup:

M@rco
11-09-2003, 08:23 PM
Crash, I have done my best to help you but we clearly don't seem to be communicating...! I hope someone else is able to help you better instead.

NEXT! :p

Crash1hd
11-10-2003, 03:56 AM
NP! I really do appreciate all the help sometimes I just cant be helped!:cool:

Crash1hd
11-10-2003, 01:46 PM
I found the following code works great! does exactly what I was looking for :cool:

this.form.target='_blank';

inside the button field as follows

<input type='submit' value='Click Here' onClick=""this.form.target='_blank';this.form.action='Purchase_Mem.asp?dbshow=4&Mtemplate="&Request.Form("Mtemplate")&"';"">

I dont know why I didnt see it sooner!:rolleyes:

Thanks anyhow!:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum