/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Update a text field

Hello,
Could someone tell me how I would go about doing the following:
I would like to be able to click on an image, and have its id inserted into a text field.
Like this:
<img src=”smile.gif” id=”?” />
insert the id into:
<input name=”text” type=”text” size=”20″/>

Any help would be appreciated. I really need this ?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@mjdamatoFeb 23.2007 — &lt;img src="smile.gif" id="xxx" onclick="document.getElementById('text').value=this.id" /&gt;

&lt;input name="text" type="text" id="text" size="20"/&gt;


Or if you need to do this for a lot of images, you should probably create a function:
<i>
</i>function populateID(fieldID, value) {
document.getElementById(fieldID).value = value;
}

<i>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</i>

&lt;img src="smile.gif" id="xxx" onclick="populateID('text',this.value);" /&gt;

&lt;input name="text" type="text" id="text" size="20"/&gt;
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 23.2007 — Thank you for your help ?
Copy linkTweet thisAlerts:
@mjdamatoFeb 23.2007 — You should leave your question intact for other people who might look at this thread
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 23.2007 — Actually I have a problem on my page can anyone help?

I have this code:
&lt;input name="submit_shout" type="text" class="textboxes" onClick="MM_setTextOfTextfield('submit_shout','','')" value="Message" size="20"/&gt;
And it is conflicting with this code.
<i>
</i>&lt;img src="images/smileys/bad.gif" width="18" height="18" id=":bad:" onclick="document.shoutbox.submit_shout.value=document.shoutbox.submit_shout.value+this.id;" /&gt;

When i click on the image it is supposed to add the image ID to the text field.

It does that, however when i click in the text field it clears it.

I still want to have the ability to clear the text field but ONLY if they text fields value is "Message".

How can this be achieved?

Thanks
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 23.2007 — Anyone?
Copy linkTweet thisAlerts:
@mjdamatoFeb 23.2007 — I still want to have the ability to clear the text field but ONLY if they text fields value is "Message".[/quote]

I'm not sure I understand. I think you are saying that when the user click in the text field you want the value in that field to be cleared IF the value is currently "Message". Is that correct? In any case, In any case, I can't help since that field is calling a function which you have not identified.
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 23.2007 — Yes that is what I mean.
&lt;script type="text/JavaScript"&gt;
&lt;!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))&gt;0&amp;&amp;parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&amp;&amp;d.all) x=d.all[n]; for (i=0;!x&amp;&amp;i&lt;d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&amp;&amp;d.layers&amp;&amp;i&lt;d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x &amp;&amp; d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

//--&gt;
&lt;/script&gt;

These functions were made using dreamweaver.
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 23.2007 — Ive got it working
×

Success!

Help @papa_face spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...