Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-29-2012, 05:28 PM   PM User | #1
kmpoaquests
New to the CF scene

 
Join Date: Apr 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kmpoaquests is an unknown quantity at this point
Question Getting values of H1 tag based on URL

Below is the code I'm using.
Essentially I need the values stored within the H1 tag based on the URL, I don't know how to get that value or if it has to be scraped.

FYI the url needed to retrieve h1 tag data can be considered a cross domain.

Little guide on the mechanics of the form.
  1. type model number in first box
    second box retrieves the value within h1 tag
    Image is shown based on which model number is typed in first box

Appreciate any and all kinds of help.
Thank You

Code:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head><body>

<form name="form1" method="post" action="">
       <p>7-digit product#
         <input type="text" name="model" id="model">
       </p>
       <p>
         <label for="description">description</label>
         <input type="text" name="description" id="description">
       </p>
       <p>
         <input name="start" type="hidden" id="start" value="http://www.mysite.com/Products/">
  </p>
       <p>
         <input name="end" type="hidden" id="end" value=".jpg">
       </p>
       <p><img name="proudctimage" src="=#start#model#end" width="32" height="32" alt=""></p>
</form>

<script>
    var model_input = document.getElementById('model');
    var start = document.getElementById('start');
    var end = document.getElementById('end');
    var image = document.getElementsByTagName('img');

    model_input.onkeyup = function(e){
       image[0].src = start.value + model_input.value + end.value; }
   </script>
   
</body>
</html>
kmpoaquests is offline   Reply With Quote
Old 05-29-2012, 09:20 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,575
Thanks: 62
Thanked 4,062 Times in 4,031 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Can't do it. You can't cross-domain screen scrape using JavaScript. Oh, there are ways to do it *IF* you can put code into the pages on BOTH domains, but not if you have no control over the foreign domain's pages.

You *can* do this using server-side code: PHP/ASP/JSP/etc.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 05-29-2012, 09:31 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
if you're really set on client-side you could maybe do it using something like the yahoo ypl - which is the page you want to scrape and where is the H1?
xelawho is offline   Reply With Quote
Reply

Bookmarks

Tags
dom, dynamic, html, javascript, jquery

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:47 AM.


Advertisement
Log in to turn off these ads.