Solved

Create a URL link based on input text

Posted on 2004-09-22
17
725 Views
Last Modified: 2012-06-27
Hey Gang,

Hopefully this is really simple.  I would like to place a text box on my page which, after some text is entered, that text is inserted into a URL, and the link is submitted.

I.E.  A user enters 1234 into a text box and clicks the "Submit" button, and is sent to "http://www.thispage.com/1234.htm"

Doesn't matter if this is done by html, dhtml, Javascript...whatever :-)

Thanks in advance!
Mike
0
Comment
Question by:Mike R.
  • 9
  • 6
  • 2
17 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
ID: 12127816
Hi rightmirem,

<form name="myForm" action="" method="post">
<input type="text" name="myURL" size="20" />
<input type="submit" value="Submit" onclick="this.form.action='http://www.thispage.com/'+this.form.myURL.value;" />
</form>

Regards,
Zyloch
0
 
LVL 3

Author Comment

by:Mike R.
ID: 12127946
Tha did it...thanks! (I new it would be simple!  This is what happens when you have Net Admins doing web pages :-)
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12127954
Heh, you need any more help, just post here. I know a lot of great EE people that're bound to help you
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 3

Author Comment

by:Mike R.
ID: 12128351
Hey...since I have your ear...two more quick things related to this form.

1. I noticed, when the enter key is pressed (as opposed to the "Sunbmit" button) it does not go to the correct link (appears not to form the URL right).  Is there a way to fix this?

2. Since the form opens up a new web page based on the input...is there a way to have the current page verify that the new page exists before loading it and, in the event it does NOT exist, go to a default page?

Thanks again!
M
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12128514
Ok. Let's see. For #1, that's my mistake.

Take the code out of the onclick in the button, and move it into onsubmit in the <form> tag taking out the 'form'

As for #2, I believe there is a way with xmlHTTP and Javascript that's supported by most recent browsers. Try this: (not tested)

function testPageExist(page) {
   var xhttp=(document.all) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
   xhttp.open("GET",page,false);
   try {
      if (document.all) {
         xhttp.send();
      } else {
         xhttp.send(null);
      }
   } catch(e) {
      return false;
   }
   return true;
}


You would have this in the onsubmit of the form:

<form onsubmit="if (testPageExist(this.myURL.value){this.action='http://www.thispage.com/'+this.myURL.value;}else{return false;}">
0
 
LVL 3

Author Comment

by:Mike R.
ID: 12128899
The "onsubmit" works great (I took out the testPage part for the first step)...but I am not sure how to add the xml to the page.  If I save the page as XML (using Frontpage) the "XML veiw" checker comes up with a bunch of errors (as this form is part of an existing webpage.)

Can I add the xml code to an existing HTML document and, if so, how?

Thanks!
Mike
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12128976
Nope, nope, don't save it as HTML. Put the function in your <script> tag on your page :)
0
 
LVL 3

Author Comment

by:Mike R.
ID: 12146621
Well, heres the problem..and if resolving this does not appear to be simple, I think I may just scrap it...

I seem to have gotten everything to work with the script EXCEPT, I actually need to verify a page by it's full URL...as this is not a page on MY site.  Basically, everything seems to be working if the "page" in "testPageExist(page)" is local to my site...but if "page"="www.differentSite.com/index.html" (or any variation, "http://www.differentSite.com/index.html", "123.123.123.123/index.com", ETC.) it fails.

Is it a syntax issue...or can this just not be done?

Thanks!
M
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12148070
It works on my computer with IE6. However, once SP2 is uploaded, and Mozilla right now, causes a permission denied error, as is common for cross domain scripting. You can accomplish this task relatively easily with server-side (I know how easily with PHP) though, so if you're interested...
0
 
LVL 3

Author Comment

by:Mike R.
ID: 12148106
Um...never mind on the last post.  For whatever reason, if I tested the page from my local hard drive, it choked...but if I actually published it to the web and tried it...it worked.

Go figure...Microsoft...:-)
M
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12148163
Heh, good for you :-)
0
 
LVL 3

Author Comment

by:Mike R.
ID: 12148172
By the way...I did some surfing, and played with the code a little (to make it http with Javascript, instead of .xml) and this is what I came up with.  I could not have done it if it weren't for your guidance!!

Thanks again and I think we can oficially call this one "solved!"
M

****************
<html>
<head>
<script type="text/javascript">
function getPage(page)
{
var objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
var testPage='http://www.city-data.com/zips/'+page+'.html'
objHTTP.Open('GET',testPage,false)
objHTTP.Send()
var test= objHTTP.status
 if (test==200){
  return true;
  } else {
  return false;
 }
}
</script>
</head>

<body>

<form onsubmit="if (getPage(this.myURL.value)) {this.action='http://www.city-data.com/zips/'+this.myURL.value+'.html';} else {this.action='http://www.city-data.com/';}" method="POST">
                  <p align="center"><input type="text" name="myURL" size="5"><input type="submit" value="Get City Info!"><br>
                  <b>Provided by <a href="http://www.city-data.com">CITY-DATA.COM</a></b><br>
                  <b>If the page comes up as unavailable, the ZIP code may not yet be
                  in City-Data's database.<br>
                  Enter a nearby ZIP, and try again!</b></p>
            </form>


</body>
</html>

*************
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12148181
No problem :). Only point I have to make was that in my original code, it should work for Mozilla Firefox and Netscape for local documents at least. That is why the xmlHttpRequest is there, because NN needs it, but in the end, it's your choice, since Mozilla doesn't seem to let you do cross-browser.
0
 

Expert Comment

by:dickarscott
ID: 12203393
I tried this also but my server, although forming the URL correctly is not giving forth the PDF document I am trying to present...

Here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PDF Roll Call Retrieval</title>
</head>
<body bgcolor="#ffffff">
<p>Retrieve Roll Call PDF
<form name="GetRollCallVote" action="" method="post">
All Roll Call Votes are in PDF&nbsp;format. Please put in the number you are looking for<br>
and add the neccessary leading zeroes to make a five digit number
<p><input type="text" name="RollCallURL" size="5">
<input type="submit" value="Get Roll Call" onclick="this.form.action='RollCallPdfs/'+this.form.RollCallURL.value+'.PDF';" >  <input type="reset" value="Clear Form Data" ></p>
            </form>
      </body>
</html>

I suspect it's may be a server thing but I reset all the necessary permissions. Do I have to add a MIME type somewhere in the code for the PDF?

Thanks
Dick
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12203417
dickarscott, not too sure how your problem pertains to this. Can you elaborate further?
0
 

Expert Comment

by:dickarscott
ID: 12205391
The question and answer is on target and formed the proper URL but it appears the server needs some config to feed up the PDF document. It appears that the server error 405 received is related to application mapping in IIS 5. The PDF called in the URL is not loading into the browser window even though mime type in browser is there.

Now it looks as though the code is correct but the PDF application mapping for that extension isn't right. When I map .pdf to AcroRd32.exe I get an invalid filepath error. I guess there must be some pdf.dll that needs to be in the right place to get the path fixed.

That's really my need.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12207363
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Safari On Gmail only html 12 58
HTML5 Get data in table rows 5 29
Changing alignment and creating border 6 30
Get Pixel color of the x and y axis Html without canvas 8 39
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question