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
  • 27,470
  • 11
  • 72
  • 109
Isbah Khan
  • 115
  • 5
  • 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,375
  • 13
  • 32
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
  • 315
  • 1
  • 2
  • 11