te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Passing multiple variables with onClick - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing multiple variables with onClick - Stack Overflow

programmeradmin5浏览0评论

I am wanting many different buttons (each written in using PHP), to pass 3 or more variables using onClick to the function to then write this into the input fields.

The following is getting close, but I am not sure how to pass up the multiple var array up to the function for the re-write..

<HTML>
<HEAD>
<TITLE>Test Input </TITLE>
<SCRIPT LANGUAGE="JavaScript">
function writeText (var1, var2, var3) {
    form.inputbox1.value = var1
    form.inputbox2.value = var2
    form.inputbox3.value = var3
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">
Enter something in the box: <BR>
<INPUT TYPE="button" NAME="button2" Value="Write" onClick="writeText(this.form)"><br>

  <input type="text" name="inputbox2"><br>
  <input type="text" name="inputbox3"><br>
  <input type="text" name="inputbox4">

</FORM>
</BODY>
</HTML>

I am wanting many different buttons (each written in using PHP), to pass 3 or more variables using onClick to the function to then write this into the input fields.

The following is getting close, but I am not sure how to pass up the multiple var array up to the function for the re-write..

<HTML>
<HEAD>
<TITLE>Test Input </TITLE>
<SCRIPT LANGUAGE="JavaScript">
function writeText (var1, var2, var3) {
    form.inputbox1.value = var1
    form.inputbox2.value = var2
    form.inputbox3.value = var3
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">
Enter something in the box: <BR>
<INPUT TYPE="button" NAME="button2" Value="Write" onClick="writeText(this.form)"><br>

  <input type="text" name="inputbox2"><br>
  <input type="text" name="inputbox3"><br>
  <input type="text" name="inputbox4">

</FORM>
</BODY>
</HTML>
Share Improve this question asked Jul 16, 2012 at 23:11 JaybestJaybest 311 gold badge1 silver badge3 bronze badges 3
  • I am not really getting your requirement here. Do you mean you want to use the writeText to be called from different buttons where some might pass just 1 value in place of 3? Can you please elaborate? – Wiz Commented Jul 16, 2012 at 23:15
  • Just find the <input> elements in the DOM. No need to pass them as parameters. – Pointy Commented Jul 16, 2012 at 23:27
  • what do u need to pass, where's this.form defined? – Moataz Elmasry Commented Jul 16, 2012 at 23:30
Add a ment  | 

2 Answers 2

Reset to default 11

If what you are trying to do is have different buttons, each of which writes a different set of values to the three fields, then there are a couple of issues.

  1. In the writeText function, you are not specifying which form should be written to (unless the 'form' variable contains the form, that is).
  2. The parameter you are passing to the writeText function is not actually one you have written the writeText function to use.


First, to write three values to the fields using the writeText function conceptually like you've written it, your button HTML should be along the lines of:

<INPUT TYPE="button" NAME="button2" Value="Write" onClick="writeText('value1','value2','value3')">

Also, you need to change the code in your 'writeText' function to point to the fields you want. One way of doing this would be to add an ID to the fields you want to write to, and then getElementById, e.g. change your fields to

<input type="text" name="inputbox1" id="inputbox1">

then in the javascript using:

var inputbox1 = document.getElementById('inputbox1');
if (inputbox1) { inputbox1.value = var1 }

So specifically, to pass the three values from the onClick to the writeText function, you need to use

onClick="writeText('value to write 1','value to write 2', 'value to write 3');"
rather than
writeText(this.form)

And how to handle -

$('#list_tasks').append('<button class="btn btn-default" onclick="buildMemberPerTask(' + res + ',' + res + ')"; type="submit">' + res.results[i].description + '</button>');
发布评论

评论列表(0)

  1. 暂无评论