0

I need to know how to call javascript functions in "src" also for

<input type=text>

I am using a function which returns querystring parameters

function GetUrlValue(VarSearch) {
            var SearchString = window.location.search.substring(1);
            var VariableArray = SearchString.split('&');
            for (var i = 0; i < VariableArray.length; i++) {
                var KeyValuePair = VariableArray[i].split('=');
                if (KeyValuePair[0] == VarSearch) {
                    return KeyValuePair[1];
                }
            }
        }

like if:

"www.testweb.com?a=521&b=http://demo.sacredpixel.com/redsky/wp/modern/wp-content/uploads/2013/05/gd-1.jpg"

so it will return on

alert(GetUrlValue('a')); ===> 521

but what i need is to call this function in img and input type 'text' tags.. like:

<iframe src="" id="well" width="100%" height="100%" />
<input type="text" value="" />

How to call function in above two?

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
Isbah Khan
  • 115
  • 7
  • 14

2 Answers2

3

I think you need this type of working. Please review it and let me know.

HTML:-

<img id="myimg" src="" />  
<input type="text" id="inputfield" value="">  

JS:-

 function GetUrlValue(VarSearch) {  
        var SearchString = window.location.search.substring(1);  
        var VariableArray = SearchString.split('&');  
        for (var i = 0; i < VariableArray.length; i++) {  
            var KeyValuePair = VariableArray[i].split('=');  
            if (KeyValuePair[0] == VarSearch) {  
                return KeyValuePair[1];  
            }  
        }  
    }  

    document.getElementById('myimg').src = GetUrlValue('b');  
    //"http://www.w3schools.com/images/w3html.gif";  
    document.getElementById('inputfield').value = GetUrlValue('a');  

Host the files and try this url:- "www.testweb.com?a=521&b=http://demo.sacredpixel.com/redsky/wp/modern/wp-content/uploads/2013/05/gd-1.jpg"

It worked for me. Hope it helps you.

Manish Gupta
  • 1,405
  • 14
  • 32
  • @IsbahKhan: Great! You can always select as answer if you find the above answer helpful. It helps other to find it quick. – Manish Gupta Feb 13 '14 at 06:57
  • @IsbahKhan : One more thing. I have voted your answer. I think now you have enough reputation to post images as well as to vote for an answer. :) Enjoy coding.. – Manish Gupta Feb 13 '14 at 07:02
  • @IsbahKhan Hello, If this answer is working for you then please tick as accepted answer. – Manish Gupta May 23 '14 at 09:55
0

Can you modify function GetUrlValue with two parameters?
This approach will solve your problem.
Pass the search id and in which text you want to find it.
There is another approach hope you will get help from it. Following Link will be help you ClickHere

Community
  • 1
  • 1
Suraj
  • 345
  • 1
  • 2
  • 12