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?

6
  • 1
    sorry it is not clear... can you explain again Commented Feb 13, 2014 at 6:09
  • i just need to call above function in input and iframe tags. Commented Feb 13, 2014 at 6:10
  • use jquery, write your function GetUrlValue, receive the value of "b" and put it in like $('#well').attr('src',b); I hope you get an idea... Commented Feb 13, 2014 at 6:12
  • when do you want to use it and what is the expected result Commented Feb 13, 2014 at 6:12
  • actually i have a single page "Blog-post", and whatever value came in querystring, i will get that value by using above function, now all i need is to call this function so that my iframe and input are loaded on the start of page. Commented Feb 13, 2014 at 6:21

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@IsbahKhan: Great! You can always select as answer if you find the above answer helpful. It helps other to find it quick.
@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..
@IsbahKhan Hello, If this answer is working for you then please tick as accepted answer.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.