Create a URL link based on input text

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
LVL 3
Mike R.Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZylochCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike R.Author Commented:
Tha did it...thanks! (I new it would be simple!  This is what happens when you have Net Admins doing web pages :-)
0
ZylochCommented:
Heh, you need any more help, just post here. I know a lot of great EE people that're bound to help you
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mike R.Author Commented:
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
ZylochCommented:
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
Mike R.Author Commented:
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
ZylochCommented:
Nope, nope, don't save it as HTML. Put the function in your <script> tag on your page :)
0
Mike R.Author Commented:
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
ZylochCommented:
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
Mike R.Author Commented:
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
ZylochCommented:
Heh, good for you :-)
0
Mike R.Author Commented:
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
ZylochCommented:
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
dickarscottCommented:
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
ZylochCommented:
dickarscott, not too sure how your problem pertains to this. Can you elaborate further?
0
dickarscottCommented:
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
ZylochCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

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.