[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Create a URL link based on input text

Posted on 2004-09-22
17
Medium Priority
?
736 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

834 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